﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JigLibX.Collision;
using JigLibX.Geometry;
using Microsoft.Xna.Framework;
using JigLibX.Physics;

namespace SolarWinds.Helpers
{
    class PhysicsHelper
    {
        /// <summary>
        /// Helper for all shapes that use physics
        /// </summary>
        /// <param name="mass">Mass of the shape</param>
        /// <param name="skin">Skin of the shape</param>
        /// <param name="body">Body of the shape</param>
        /// <returns>Center of Mass</returns>
        public static Vector3 SetMass(float mass, CollisionSkin skin, Body body)
        {
            var primitiveProperties = new PrimitiveProperties(
                PrimitiveProperties.MassDistributionEnum.Solid,
                PrimitiveProperties.MassTypeEnum.Mass, mass);

            float junk;
            Vector3 com;
            Matrix it;
            Matrix itCoM;

            skin.GetMassProperties(primitiveProperties, out junk, out com, out it, out itCoM);

            body.BodyInertia = itCoM;
            body.Mass = junk;

            return com;
        }
    }
}
